var admin_main_apis = {
    changepassword: "http://api.fangchepingtai.com/fangchebbs/admin/changepassword",
    verifycode: "http://api.fangchepingtai.com/fangchebbs/bmob/requestSmsCode/",
    adminupdata: "http://api.fangchepingtai.com/fangchebbs/admin/update"
};
(function() {
    // 修改密码
    App.set("$Event.admin.main.changepassword", function() {
        var data = App.get("$Cache.admin.main.password");
        coAjax.put(admin_main_apis.changepassword, data || {}, function(result) {
            alert("success", "密码修改成功");
        }, function(err, errMsg) {
            alert("warn", errMsg);
        });
    });
    // 获取修改密码验证码
    App.set("$Event.admin.main.get_password_verifycode", function() {
        coAjax.get(admin_main_apis.verifycode + "admin_veri", {
            mobilePhoneNumber: App.get("admin.mobile")
        }, function() {
            alert("success", "验证码获取成功");
            var _i = 180;
            var _t = setInterval(function() {
                _i == 0 ? clearInterval(_t) : false;
                App.set("$Cache.admin.main.password_verifycodelimit", _i);
                _i--;
            }, 1000);
        }, function(err, errMsg) {
            alert("warn", errMsg);
            console.log(errMsg);
        })
    });
    // 修改管理员信息
    App.set("$Event.admin.main.changeadmininfo", function() {
        var data = App.get("admin");
        coAjax.put(admin_main_apis.adminupdata, data, function(result) {
            alert("success", "管理员信息已更新");
            // console.log(result);
            App.set("admin", result);
        }, function(err, errMsg) {
            alert("warn", errMsg);
        });
    });
    // 获取修改信息验证码
    App.set("$Event.admin.main.get_info_verifycode", function() {
        coAjax.get(admin_main_apis.verifycode + "admin_veri", App.get("admin"), function() {
            alert("success", "验证码获取成功");
            var _i = 180;
            var _t = setInterval(function() {
                _i == 0 ? (clearInterval(_t), App.set("$Cache.admin.main.info_verifycodelimit", false)) : false;
                App.set("$Cache.admin.main.info_verifycodelimit", _i);
                _i--;
            }, 1000);
        }, function(err, errMsg) {
            alert("warn", errMsg);
        });
    });
}());
